package com.chencong.test;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author chencong
 * @date 2020/12/11 下午3:13
 */
public class HandlerServerThreadPool {
    // 线程池
    private ExecutorService executor;

    // 线程池：线程数量  队列数量
    public HandlerServerThreadPool(int maxPoolSize, int queueSize) {
        executor = new ThreadPoolExecutor(
                maxPoolSize,//常在线程数量
                maxPoolSize,//最大线程数量
                10L,//等候时间
                TimeUnit.SECONDS,//等候时间单位
                new ArrayBlockingQueue<Runnable>(queueSize));//任务队列(队列数量)
    }

    public void execute(Runnable task) {
        this.executor.execute(task);
    }
}
